<template>
    <div class="leftbox">
        <div class="top">
            <dv-border-box-13>
                <div style="padding:20px;">
                    <div class="title">
                        <img src="../../../public/Government/icon.png" >
                        <span>正在受理</span>
                    </div>
                    <div style="display: flex;justify-content: space-between;margin:10px 0">
                        <span>正在受理<span style="font-size: 26px;color: #f59a23;"> {{ currentProcessing }} </span>人次</span>
                        <span>前方等待<span style="font-size: 26px; color: #04f21c;"> {{ waiting }} </span>人次</span>
                    </div>
                    <div class="person">
                        <img src="../../../public/Government/green.png" v-for="item in 9" :key="item" >
                        <img src="../../../public/Government/orange.png" v-for="item in 15" :key="item" >
                    </div>
                    <span>33%/67%</span>
                </div>
            </dv-border-box-13>
        </div>
        <div class="bottom">
            <dv-border-box-13>
                <div style="padding:20px;">
                    <div class="title">
                        <img src="../../../public/Government/icon.png" alt="">
                        <span>实时受理</span>
                    </div>
                    <div>
                        <div v-for="item in realTimeData" :key="item.id" class="d-flex">
                            <img :src="item.icon">
                            <span style="display: block; width: 115px;">{{ item.name }}</span>
                            <span class="num">{{ item.value }}</span>
                            <span>{{ item.title }}</span>
                        </div>

                    </div>
                </div>
            </dv-border-box-13>
        </div>
    </div>
</template>

<script setup>
import { ref, onMounted, onBeforeUnmount } from 'vue';

const currentProcessing = ref(17); // 正在受理人数
const waiting = ref(31) // 前方等待人数
let countdownTimer = null; //2s
let waitTimer = null; // 4s
let takeNumberTimer = null; //1s

onMounted(() => {
    countdownTimer = setInterval(() => {
        // 受理倒计时
        if (currentProcessing.value > 0) {
            currentProcessing.value--;
        }
        const firmNumberItem = realTimeData.value.find(item => item.name === '新注册企业');
        const trafficNumberItem = realTimeData.value.find(item => item.name === '交管违章处理');
        const cardNumberItem = realTimeData.value.find(item => item.name === '市民卡');
        if (firmNumberItem) {
            firmNumberItem.value++;
        }
        if (trafficNumberItem) {
            trafficNumberItem.value++;
        }
        if (cardNumberItem) {
            cardNumberItem.value++;
        }
    }, 2000); 
    waitTimer = setInterval(() => {
        if (waiting.value > 0) {
            waiting.value--;
        }
        const proingNumberItem = realTimeData.value.find(item => item.name === '正在受理');
        const licenseNumberItem = realTimeData.value.find(item => item.name === '证照联办');
        const dealNumberItem = realTimeData.value.find(item => item.name === '不动产交易');
        if (proingNumberItem) {
            proingNumberItem.value++;
        }
        if (licenseNumberItem) {
            licenseNumberItem.value++;
        }
        if (dealNumberItem) {
            dealNumberItem.value++;
        }
    }, 3000);

    takeNumberTimer = setInterval(() => {
        const takeNumberItem = realTimeData.value.find(item => item.name === '今日取号');
        const processNumberItem = realTimeData.value.find(item => item.name === '今日受理');
        const waitingNumberItem = realTimeData.value.find(item => item.name === '前方等待');
        const hosNumberItem = realTimeData.value.find(item => item.name === '医保社保');
        if (takeNumberItem) {
            takeNumberItem.value++;
        }
        if (processNumberItem) {
            processNumberItem.value++;
        }
        if (waitingNumberItem) {
            waitingNumberItem.value--;
        }
        if (hosNumberItem) {
            hosNumberItem.value++;
        }
    }, 1000);
});

// 组件卸载时清除定时器
onBeforeUnmount(() => {
    if (countdownTimer) {
        clearInterval(countdownTimer);
    }
    // 清除今日取号定时器
    if (takeNumberTimer) {
        clearInterval(takeNumberTimer);
    }
});

const realTimeData = ref([
    {
        id: 1,
        icon: require("../../../public/Government/one.png"),
        name: '今日取号',
        value: 100, 
        title: "人次"
    },
    {
        id: 2,
        icon: require("../../../public/Government/two.png"),
        name: '今日受理',
        value: 201,
        title: "人次"
    },
    {
        id: 3,
        icon: require("../../../public/Government/three.png"),
        name: '正在受理',
        value: 190,
        title: "人次"
    },
    {
        id: 4,
        icon: require("../../../public/Government/four.png"),
        name: '前方等待',
        value: 331,
        title: "人次"
    },
    {
        id: 5,
        icon: require("../../../public/Government/five.png"),
        name: '新注册企业',
        value: 200,
        title: "家"
    },
    {
        id: 6,
        icon: require("../../../public/Government/six.png"),
        name: '证照联办',
        value: 100,
        title: "件"
    },
    {
        id: 7,
        icon: require("../../../public/Government/seven.png"),
        name: '医保社保',
        value: 200,
        title: "人次"
    },
    {
        id: 8,
        icon: require("../../../public/Government/eight.png"),
        name: '交管违章处理',
        value: 100,
        title: "件"
    },
    {
        id: 9,
        icon: require("../../../public/Government/nine.png"),
        name: '不动产交易',
        value: 200,
        title: "件"
    },
    {
        id: 10,
        icon: require("../../../public/Government/ten.png"),
        name: '市民卡',
        value: 100,
        title: "件"
    },




])

</script>

<style scoped lang="scss">
.title {
    width: 60%;
    display: flex;
    align-items: center;
    background-color: #052e63;
    border-radius: 50px 15px 0 50px;

    img {
        width: 35px;
        height: 40px;
    }

    span {
        display: block;
        padding: 10px;
        font-weight: bold;
        color: white;
    }

}

.leftbox {
    padding: 15px;
    width: 100%;
    .top {
        width: 100%;
        height: 340px;
        background-color: #07164ebe;

        span {
            font-size: 19px;
        }
        .person {
            margin: 10px 0;

            img {
                width: 50px;
                height: 50px;
                margin-top: 10px;
            }
        }

    }

    .bottom {
        width: 100%;
        background-color: #07164ebe;
        margin-top: 20px;

        span {
            font-size: 19px;
        }

        .d-flex {
            display: flex;
            gap: 30px;
            align-items: center;
            margin: 14px 0;
            color: #62a2cc;
            img {
                width: 30px;
                height: 30px;
            }
            .num{
                display: block;
                width: 100px;
                padding: 6px 0;
                text-align: center;
                background-color: #036399;
                color: white;

            }
        }

    }
}
</style>
